﻿@using SCMS.Resource
@model SCMS.UI.Models.OtherConsumables
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "AssetsDiv",
      LoadingElementId = "loading",
      HttpMethod = "Post",
      Url = Url.Action(@ViewBag.Action),
      OnSuccess = "usermsg(); if (document.getElementById('table') != null) {initSorter();sorter.size(20);}ClearFormById('#' + 'otherConsumable');",
      OnFailure = "javascript:errormsg()"

  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="partialViewCard">
    <div class="partialViewCardHeader"><h3>@Resources.GoodsReceivedNote_LoadOtherConsumables_Header</h3></div>
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form", @id = "otherConsumable" }))
    {
        @Html.ValidationSummary(true)
        <br />
        <input type="hidden" id="actionStatus" value="@ViewBag.Response" />
        <input type="hidden" id="statusMsg" value="@ViewBag.msg" />
        @Html.HiddenFor(x => x.EntityInventory.CountryProgrammeId)
        <table width="50%" align="center" cellpadding="2">
            @Html.HiddenFor(x => x.EntityInventory.Id)
            <tr>
                <td align="right" valign="top" style="font-weight: bold;">
                    @Resources.Global_String_Warehouse
                </td>
                <td align="left" class="editor-field">
                    @Html.DropDownListFor(x => x.Warehouse, Model.Warehouses, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.Warehouse, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <td align="right" valign="top" style="font-weight: bold;">
                    @Resources.Global_String_ItemName:
                </td>
                <td align="left" class="editor-field">
                    @Html.DropDownListFor(x => x.ItemId, Model.Items, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.ItemId, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <td align="right" valign="top" style="font-weight: bold;">
                    @Resources.Global_String_Quantity:
                </td>
                <td align="left" class="editor-field">
                    @Html.TextBoxFor(x => x.Quantity, new { @class = "numericTb" })
                    @Html.ValidationMessageFor(x => x.Quantity, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <td align="center" colspan="2">
                    <input type="submit" class="btn green" value="@Resources.GoodsReceivedNote_LoadOtherConsumables_UpdateInventory" />
                </td>
            </tr>
        </table>        
    }
    <hr />
    @if (Model.Inventories.Count() > 0)
    {
        <div id="tablewrapper">
            <div id="tableheader">
                <div class="search">
                    <b>@Resources.Global_String_SearchBy:</b><br />
                    <select id="columns" onchange="sorter.search('query')">
                    </select>
                    <input type="text" id="query" onkeyup="sorter.search('query')" />
                </div>
                <span class="details">
                    <div>
                        @Resources.Global_String_Records <span id="startrecord"></span>-<span id="endrecord"></span> @Resources.Global_String_Of <span id="totalrecords">
                        </span>
                    </div>
                </span>
            </div>
            <br />
            <br />
            <table width="98%" align="center" cellpadding="0" cellspacing="0" border="0" id="table"
                class="tinytable">
                <thead>
                    <tr class="gridheader">
                        <th>
                            <h3>@Resources.Global_String_ItemName</h3>
                        </th>
                        <th>
                            <h3>@Resources.Global_String_UnitsOfMeasure</h3>
                        </th>
                        <th>
                            <h3>@Resources.GoodsReceivedNote_LoadOtherConsumables_ExistingQuantity</h3>
                        </th>
                        <th>
                            <h3>@Resources.Global_String_Warehouse</h3>
                        </th>
                        <th>
                            <h3>@Resources.Global_String_Manage</h3>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.Inventories)
                    {             
                        <tr>
                            <td>
                                @item.Item.Name
                            </td>
                            <td align="center">
                                @item.Item.UnitOfMeasure.Code
                            </td>
                            <td align="right">
                                @item.Quantity.ToString("#,##0")
                            </td>
                            <td>@item.WareHouse.Name
                            </td>
                            <td align="center">
                                @Ajax.ActionLink(Resources.Global_String_Edit, "LoadEditConsumables", new { @iventId = item.Id }, new AjaxOptions
                            {
                                UpdateTargetId = "AssetsDiv",
                                LoadingElementId = "loading",
                                OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(20);}"

                            }) |
                                @Ajax.ActionLink(Resources.Global_String_Remove, "RemoveConsumableItem", new { @iventId = item.Id }, new AjaxOptions
                            {
                                UpdateTargetId = "AssetsDiv",
                                LoadingElementId = "loading",
                                Confirm = Resources.GoodsReceivedNote_LoadOtherConsumables_ConfirmRemove,
                                OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(20);}"
                            })
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <div id="tablefooter">
                <div id="tablenav">
                    <div>
                        <img src="../../Content/images/pager/first.gif" width="16" height="16" alt="@Resources.Global_String_FirstPage"
                            onclick="sorter.move(-1,true)" />
                        <img src="../../Content/images/pager/previous.gif" width="16" height="16" alt="@Resources.Global_String_PreviousPage"
                            onclick="sorter.move(-1)" />
                        <img src="../../Content/images/pager/next.gif" width="16" height="16" alt="@Resources.Global_String_NextPage"
                            onclick="sorter.move(1)" />
                        <img src="../../Content/images/pager/last.gif" width="16" height="16" alt="@Resources.Global_String_LastPage"
                            onclick="sorter.move(1,true)" />
                    </div>
                    <div>
                        <select id="pagedropdown">
                        </select>
                    </div>
                    <div>
                        <a href="javascript:sorter.showall()">@Resources.Global_String_ViewAll</a>
                    </div>
                </div>
                <div id="tablelocation">
                    <div>
                        <select onchange="sorter.size(this.value)">
                            <option value="5">5</option>
                            <option value="10">10</option>
                            <option value="20" selected="selected">20</option>
                            <option value="50">50</option>
                            <option value="100">100</option>
                        </select>
                        <span>@Resources.Global_String_EntriesPerPage</span>
                    </div>
                    <div class="page">
                        @Resources.Global_String_Page <span id="currentpage"></span>@Resources.Global_String_Of <span id="totalpages"></span>
                    </div>
                </div>
            </div>
        </div>            
    }
    <br />
</div>
